//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    serviceItem:[],
    conf_data:[]

  },
  servicebind:function(e){  
    
    wx.navigateTo({
      url: "/pages/hairdresser/hairdresser?itemId=" + e.currentTarget.id
    });
    
  },
 
 
  onLoad: function () {
    
    
    var that = this;

    var login_code = wx.getStorageSync("login_code");
    var userInfo = wx.getStorageSync("userInfo");
    that.setData({
      userInfo: userInfo
    });
    //调用应用实例的方法获取全局数据
    console.log(wx.getStorageSync("login_code"));

      wx.showLoading({
        title: '加载中',
      });
      wx.request({
        url: app.globalData.api_url + "index.php?ac=mfapi&ts=onlogin",
        data: { code: login_code, nickName: userInfo.nickName, picture: userInfo.avatarUrl},
        method: "POST",
        header: { 'content-type': 'application/json' },
        success:function(rs){
         
          wx.setStorageSync('_openid', rs.data.openid);
          wx.setStorageSync('_session_key', rs.data.session_key);
          wx.setStorageSync('_hairdresser_id', rs.data.hairdresser_id);
          wx.setStorageSync('_ism', rs.data.ism);
        }
      })

      wx.request({
        url: app.globalData.api_url + "index.php?ac=mfapi&ts=setting_all",
        data: {},
        method: "GET",
        header: { 'content-type': 'application/json' },
        success: function (res) {

          that.setData({
            conf_data: res.data

          });
        }
      });
    //获取配置信息


      

      wx.request({
        url: app.globalData.api_url +"index.php?ac=mfapi&ts=serv_get_all",
        data:{},
        header: { 'content-type': 'application/json'},
        success:function(res)
        {
          wx.hideLoading();
         
          that.setData({

            serviceItem: res.data
          })
          
        }
        
      })
      , setTimeout(function () {
        wx.hideLoading()
      }, 2000)
  }
})
